package org.hamster.common.debugger
{
	import mx.logging.ILogger;
	
	public class DebugProfileImpl implements IDebugProfile
	{
		private var _startTime:Date;
		private var _time:Date;
		private var _logger:ILogger;
		
		public function DebugProfileImpl()
		{
		}
		
		public function start(message:String = "start", logger:ILogger=null):void
		{
			_startTime = new Date();
			_time = new Date();
			_logger = logger;
			traceMessage("::Debug start ", 0, message);
		}
		
		public function traceTime(message:String = "trace"):void
		{
			var oldMs:Number = _time.milliseconds;
			_time = new Date();
			traceMessage("::Debug trace ", _time.milliseconds - oldMs, message);
		}
		
		public function end(message:String = "end"):void
		{
			traceMessage("::Debug  end  ", new Date().milliseconds - _startTime.milliseconds, message);
		}
		
		private function traceMessage(prefix:String, ms:Number, message:String):void
		{
			var msg:String = prefix + " " + ms + "ms, " + message;
			if (_logger) {
				_logger.info(msg);
			} else {
				trace(msg);
			}
		}
	}
}